<?
##########################################################################
#		DOCUMENTATION
##########################################################################
# Class that extends the rootclass. This module will provide the methods
# needed to every page that sends data to the server.
#
# © LiberLab group, 2011
##########################################################################

require_once("root.php");

class SendData extends Root{
	
	public function renderHidden(){
		# gives some value to the script that processes the data
		# (we can't use sessions because the user may not be logged)
		$this->tagHash["idHiddenINDEX§§§§idHiddenINDEX§§§§valueHiddenINDEX"] = count($_REQUEST);
		$keys = array_keys($_REQUEST);
		for($index = 0; $index < count($_REQUEST); $index++){
			$key = $keys[$index];
			$value = $_REQUEST[$key];
			$this->tagHash["idHidden$index"] = $key;
			$this->tagHash["valueHidden$index"] = $value;
		}
	}
	public function warnBoxManager($errors){
		# renders the warnBox if is needed
		$this->tagHash["warnBoxContent"] = "";
		$this->tagHash["warnBoxClass"] = "notInScreen";
		foreach($errors as $key => $error){
			if ($error){
				$this->tagHash["warnBoxContent"] = $this->messages[$key];
				$this->tagHash["warnBoxClass"] = "warnBox";
			}
		}
	}
	
	################################### FRONT END METHODS ###################################
	
	public function queryBuilder($builderArray){
		# build a link used to redirect the user to the correct page
		$query = $this->defaultScriptName . "?";
			foreach($_REQUEST as $key => $value){
				if (!in_array($key, $builderArray)){
					$query = $query . "&$key=$value";
				}
			}
		return $query;
	}
	
	public function queryFinalize($checkArray, $query){
		# clean the regex built
		$query = str_replace("?&", "?", $query); 
		if (isset($this->check)){
			$query = $query . $this->check;
		}
		return $query;
	}
	
	public function checkInsert($check, $value){
		# check is a true or false value.
		# if true, stored the error to report (the check is
		# like "if not nickname")
		if (!isset($this->check) and $check){
			$this->check = $value;
		}
	}
		
	public function __destruct() {
		parent::__destruct();
	}
};

?>
